package com.uuah.server.config.spring.parsers.delegate;

import com.uuah.server.config.spring.parsers.IUuahDefinitionParser;
import com.uuah.server.config.spring.parsers.IUuahDefinitionParserConfiguration;
import com.uuah.server.config.spring.parsers.UuahChildDefinitionParser;

public class SingleParentFamilyDefinitionParser extends
		AbstractSingleParentFamilyDefinitionParser {

	public SingleParentFamilyDefinitionParser(IUuahDefinitionParser parent) {
		// avoid the overriden method here
		super.addDelegate(parent);
		parent.setIgnoredDefault(false);
	}

	protected IUuahDefinitionParserConfiguration addDelegate(
			IUuahDefinitionParser delegate) {
		throw new UnsupportedOperationException(
				"Delegates must be associated with attribute names");
	}

	public SingleParentFamilyDefinitionParser addChildDelegate(
			String attribute, UuahChildDefinitionParser delegate) {
		return addChildDelegate(new String[] { attribute }, delegate);
	}

	public SingleParentFamilyDefinitionParser addChildDelegate(
			String[] attributes, UuahChildDefinitionParser delegate) {
		super.addChildDelegate(delegate);
		delegate.setIgnoredDefault(true);
		for (int i = 0; i < attributes.length; i++) {
			getDelegate(0).addIgnored(attributes[i]);
			delegate.removeIgnored(attributes[i]);
		}
		return this;
	}

}
